import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {SportDetailPage} from "../sport-detail/sport-detail";
import {Login} from "../login/login";
import {CheckUtil} from "../../common/CheckUtil";
import {LOCAL_SPORT_TYPE_IMG_PATH} from "../../providers/Constants";
import {SportService} from "../../providers/SportService";
import {UserInfo} from "../../model/UserInfo";
import {StorageService} from "../../providers/StorageService";

@IonicPage()
@Component({
  selector: 'page-lovesports',
  templateUrl: 'lovesports.html',
})
export class LovesportsPage {

  localSportTypeImgPath:string;
  sportList:any;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public checkUtil:CheckUtil,
              public sportService:SportService,
              public storageService:StorageService) {

    this.localSportTypeImgPath = LOCAL_SPORT_TYPE_IMG_PATH;
  }

  ionViewDidLoad() {
    this.getLoveSportList();
  }

  //打开运动详情
  goToSportDetail(id){
    if(this.checkUtil.checkUserLogin()){
      this.navCtrl.push(SportDetailPage,{id:id});
    }else {
      this.navCtrl.push(Login,{page:"PublishSport"});//跳转登录
    }
  }
  getLoveSportList(){
    if(this.checkUtil.checkUserLogin()){
      var userId = this.storageService.read<UserInfo>('UserInfo').id;
      this.sportService.loveSports(userId).subscribe(res => {
        this.sportList = res["data"];
      })
    }

  }
}
